package com.qms.qep.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qms.common.annotation.Log;
import com.qms.common.core.controller.BaseController;
import com.qms.common.core.domain.AjaxResult;
import com.qms.common.enums.BusinessType;
import com.qms.qep.domain.ProcessType;
import com.qms.qep.service.IProcessTypeService;
import com.qms.common.utils.poi.ExcelUtil;
import com.qms.common.core.page.TableDataInfo;

/**
 * 工序类型Controller
 * 
 * @author qep
 */
@RestController
@RequestMapping("/qep/processType")
public class ProcessTypeController extends BaseController
{
    @Autowired
    private IProcessTypeService processTypeService;

    /**
     * 查询工序类型列表
     */
    @PreAuthorize("@ss.hasPermi('qep:processType:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProcessType processType)
    {
        startPage();
        List<ProcessType> list = processTypeService.selectProcessTypeList(processType);
        return getDataTable(list);
    }

    /**
     * 导出工序类型列表
     */
    @PreAuthorize("@ss.hasPermi('qep:processType:export')")
    @Log(title = "工序类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProcessType processType)
    {
        List<ProcessType> list = processTypeService.selectProcessTypeList(processType);
        ExcelUtil<ProcessType> util = new ExcelUtil<ProcessType>(ProcessType.class);
        return util.exportExcel(list, "工序类型数据");
    }

    /**
     * 获取工序类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('qep:processType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(processTypeService.selectProcessTypeById(id));
    }

    /**
     * 新增工序类型
     */
    @PreAuthorize("@ss.hasPermi('qep:processType:add')")
    @Log(title = "工序类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProcessType processType)
    {
        return toAjax(processTypeService.insertProcessType(processType));
    }

    /**
     * 修改工序类型
     */
    @PreAuthorize("@ss.hasPermi('qep:processType:edit')")
    @Log(title = "工序类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProcessType processType)
    {
        return toAjax(processTypeService.updateProcessType(processType));
    }

    /**
     * 删除工序类型
     */
    @PreAuthorize("@ss.hasPermi('qep:processType:remove')")
    @Log(title = "工序类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(processTypeService.deleteProcessTypeByIds(ids));
    }
    
    /**
     * 获取工序类型树列表
     */
    @PreAuthorize("@ss.hasPermi('qep:processType:list')")
    @GetMapping("/treeList")
    public AjaxResult treeList()
    {
        List<ProcessType> list = processTypeService.selectProcessTypeTreeList();
        return success(list);
    }
} 